package com.brsya.movie.util;

import android.content.Context;

import com.brsya.base.base.Contents;
import com.brsya.movie.R;
import com.bytedance.sdk.openadsdk.TTAdConfig;
import com.bytedance.sdk.openadsdk.TTAdConstant;
import com.bytedance.sdk.openadsdk.TTAdSdk;
import com.bytedance.sdk.openadsdk.TTCustomController;

/**
 * Created by Brsya
 * CreateDate: 2022/4/18  9:11
 * Description:
 * 穿山甲广告SDK
 */
public class TTAdManagerHolder {

    private static TTAdManagerHolder holder;

    private TTAdManagerHolder() {
    }

    public static TTAdManagerHolder get() {
        if (holder == null) {
            holder = new TTAdManagerHolder();
        }
        return holder;
    }

    public void init(Context context, TTAdSdk.InitCallback callback) {
        TTAdSdk.init(context, buildConfig(context), callback);
    }


    public TTAdConfig buildConfig(Context context){

        return new TTAdConfig.Builder()
                .appId(Contents.APP_ID)
                .appName(context.getString(R.string.app_name))
                .paid(true)
                //添加这个控制之后可能造成模拟器闪退/不能下载文件
                .customController(new TTCustomController() {
                    @Override
                    public boolean isCanUseLocation() {
                        return super.isCanUseLocation();
                    }

                    @Override
                    public boolean isCanUsePhoneState() {
                        return super.isCanUsePhoneState();
                    }

                    @Override
                    public boolean isCanUseWifiState() {
                        return super.isCanUseWifiState();
                    }

                    @Override
                    public boolean isCanUseWriteExternal() {
                        return super.isCanUseWriteExternal();
                    }
                })
                //是否允许sdk展示通知栏提示
                .allowShowNotify(true)
                //测试
                .debug(Contents.DEBUG)
                //允许直接下载的网络状态集合
                .directDownloadNetworkType(TTAdConstant.NETWORK_STATE_WIFI, TTAdConstant.NETWORK_STATE_3G, TTAdConstant.NETWORK_STATE_4G)
                // 是否支持多进程
                .supportMultiProcess(false)
                .needClearTaskReset()
                .build();
    }


}
